//
//  BaseTableViewController.swift
//  ZYBWeibo
//
//  Created by xthink4 on 16/2/23.
//  Copyright © 2016年 zyb. All rights reserved.
//
import UIKit
/**
 1.判断用户是否登陆
 2.如果登陆执行正常的功能
 3.如果没有登陆替换掉视图 View
**/
var userLogin=false //用户是否登陆标示（true  登陆   false  没有登陆）
class BaseTableViewController: UITableViewController,VisitorLoginViewDelegate{

    
    var visitorView:VisitorLoginView?
    override func loadView() {
        super.loadView()
        let login=NSUserDefaults.standardUserDefaults().objectForKey("userName")
        if login==nil{
            userLogin=false
        }else{
            userLogin=true
        }
        if userLogin {   //如果登陆，直接返回
          return
        }
        //如果咩有登陆替换视图
            visitorView=NSBundle.mainBundle().loadNibNamed("VisitorLoginView", owner: nil, options: nil).last as? VisitorLoginView
         //实现代理
        visitorView?.delegate=self
        view=visitorView
        self.navigationItem.leftBarButtonItem=UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "VisitorViewRegistDidSelected")
        self.navigationItem.rightBarButtonItem=UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "VisitorViewLoginDidSelected")
    }
    ///未登录，点击登录协议
    func VisitorViewLoginDidSelected() {
        print("\(__FUNCTION__)")
        let sb=UIStoryboard(name: "OAuth", bundle: nil)
        let auth:UIViewController=sb.instantiateInitialViewController()! as UIViewController
        presentViewController(auth, animated: true, completion: nil)
    }
    ///点击注册协
    func VisitorViewRegistDidSelected() {
        print("\(__FUNCTION__)")
    }
}
